package com.yootk.common.util;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class DateConvert {
    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    private DateConvert() {
    }

    public static Date stringToDate(String str) {
        LocalDateTime dateTime = LocalDateTime.parse(str, FORMATTER);
        ZoneId zoneId = ZoneId.systemDefault();        // 得到系统当前时区
        Instant instant = dateTime.atZone(zoneId).toInstant(); // 获取日期实例
        Date date = Date.from(instant);        // 格式转换
        return date;
    }
}
